<template>
  <a-breadcrumb class="breadcrumb">
    <a-breadcrumb-item v-for="(item, index) in breadList" :key="index">
      <router-link v-if="item.name != name" :to="{ name: item.name }"><span
          class="history-title">{{ item.meta.title }}</span>
      </router-link>
      <span v-else class="current-title">{{ item.meta.title }}</span>
    </a-breadcrumb-item>
  </a-breadcrumb>
</template>

<script>
export default {
  data () {
    return {
      name: '',
      breadList: []
    }
  },
  created () {
    this.getBreadcrumb()
  },
  methods: {
    getBreadcrumb () {
      this.breadList = []
      console.log(this.$route)
      this.name = this.$route.name
      this.$route.matched.forEach((item, index) => {
        if (index > 0) {
          this.breadList.push(item)
        }
      })
    }
  },
  watch: {
    $route () {
      this.getBreadcrumb()
    }
  }
}
</script>

<style lang="less" scoped>
.breadcrumb {
  .history-title {
    color: @placeholder-color;
  }
  .current-title {
    color: @primary-color;
    font-weight: 500;
  }
}
</style>
